home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWViewAs.cpp < prev   
Encoding:
Text File  |  1995-11-08  |  9.7 KB  |  332 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWViewAs.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWVIEWAS_H
  13. #include "FWViewAs.h"
  14. #endif
  15.  
  16. #ifndef FWSTDDEF_H
  17. #include "FWStdDef.h"
  18. #endif
  19.  
  20. // ----- OS Layer -----
  21.  
  22. #ifndef FWRECSHP_H
  23. #include "FWRecShp.h"
  24. #endif
  25.  
  26. #ifndef FWPOLY_H
  27. #include "FWPoly.h"
  28. #endif
  29.  
  30. #ifndef FWPOLYSH_H
  31. #include "FWPolySh.h"
  32. #endif
  33.  
  34. #ifndef FWREGION_H
  35. #include "FWRegion.h"
  36. #endif
  37.  
  38. #ifndef FWBMPSHP_H
  39. #include "FWBmpShp.h" 
  40. #endif
  41.  
  42. #ifndef FWCFMRES_H
  43. #include "FWCFMRes.h"
  44. #endif
  45.  
  46. #ifndef FWRECT_H
  47. #include "FWRect.h"
  48. #endif
  49.  
  50. #ifndef FWICONSH_H
  51. #include "FWIconSh.h"
  52. #endif
  53.  
  54. #ifndef FWODGEOM_H
  55. #include "FWODGeom.h"
  56. #endif
  57.  
  58. // ----- Framework Layer -----
  59.  
  60. #ifndef FWFRAME_H
  61. #include "FWFrame.h"
  62. #endif
  63.  
  64. #ifndef FWPART_H
  65. #include "FWPart.h"
  66. #endif
  67.  
  68. #ifndef FWUTIL_H
  69. #include "FWUtil.h"
  70. #endif
  71.  
  72. // ----- Platform Includes -----
  73.  
  74. #if defined(FW_BUILD_MAC) && !defined(__ICONS__)
  75. #include <Icons.h>
  76. #endif
  77.  
  78. //========================================================================================
  79. // RunTime Info
  80. //========================================================================================
  81.  
  82. #if FW_LIB_EXPORT_PRAGMAS
  83. #pragma lib_export on
  84. #endif
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment fwpart2
  88. #endif
  89.  
  90. //========================================================================================
  91. // CLASS FW_CViewAs
  92. //========================================================================================
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_CViewAs::FW_CViewAs
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_CViewAs::FW_CViewAs(Environment *ev, FW_CPart* part) :
  99.     fPart(part),
  100.     fShape(NULL)
  101. {
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. //    FW_CViewAs::~FW_CViewAs
  106. //----------------------------------------------------------------------------------------
  107.  
  108. FW_CViewAs::~FW_CViewAs()
  109. {
  110.     delete fShape;
  111.     fShape = NULL;
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    FW_CViewAs::Draw
  116. //----------------------------------------------------------------------------------------
  117.  
  118. void FW_CViewAs::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  119. {
  120.     FW_ASSERT(fShape);
  121.  
  122.     FW_CFacetContext fc(ev, facet, invalidShape);
  123.     fShape->Render(fc);
  124. }
  125.  
  126. //========================================================================================
  127. // CLASS FW_CViewAsThumbnail
  128. //========================================================================================
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    FW_CViewAsThumbnail::FW_CViewAsThumbnail
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_CViewAsThumbnail::FW_CViewAsThumbnail(Environment *ev, FW_CPart* part) :
  135.     FW_CViewAs(ev, part)
  136. {
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    FW_CViewAsThumbnail::~FW_CViewAsThumbnail
  141. //----------------------------------------------------------------------------------------
  142.  
  143. FW_CViewAsThumbnail::~FW_CViewAsThumbnail()
  144. {
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. //    FW_CViewAsThumbnail::RenderThumbnailFrame
  149. //----------------------------------------------------------------------------------------
  150.  
  151. void FW_CViewAsThumbnail::RenderThumbnailFrame(Environment* ev, FW_CGraphicContext& gc)
  152. {
  153.     FW_CPoint flap[3] =
  154.         {
  155.             FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(16)),
  156.             FW_CPoint(FW_IntToFixed(32), FW_IntToFixed( 0)),
  157.             FW_CPoint(FW_IntToFixed(32), FW_IntToFixed(16))
  158.         };
  159.  
  160.     FW_PPolygon polygon2(3, flap);
  161.     FW_CPolygonShape::RenderPolygon(gc, polygon2, FW_kFill, FALSE, FW_kRGBLightGray);
  162.  
  163.     FW_CPoint thumbnailContour[8] =
  164.         {
  165.             FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(16)),
  166.             FW_CPoint(FW_IntToFixed(32), FW_IntToFixed( 0)),
  167.             FW_CPoint(FW_IntToFixed( 0), FW_IntToFixed( 0)),
  168.             FW_CPoint(FW_IntToFixed( 0), FW_IntToFixed(63)),
  169.             FW_CPoint(FW_IntToFixed(47), FW_IntToFixed(63)),
  170.             FW_CPoint(FW_IntToFixed(47), FW_IntToFixed(16)),
  171.             FW_CPoint(FW_IntToFixed(32), FW_IntToFixed(16)),
  172.             FW_CPoint(FW_IntToFixed(32), FW_IntToFixed( 0))
  173.         };
  174.  
  175.     FW_PPolygon polygon(8, thumbnailContour);
  176.     FW_CPolygonShape::RenderPolygon(gc, polygon, FW_kFrame, FALSE);
  177. }
  178.  
  179. //----------------------------------------------------------------------------------------
  180. //    FW_CViewAsThumbnail::Load
  181. //----------------------------------------------------------------------------------------
  182.  
  183. void FW_CViewAsThumbnail::Load(Environment* ev, FW_CFrame* frame)
  184. {
  185.     if (fShape == NULL)
  186.     {
  187.         FW_CRect rect(FW_kZeroPoint, FW_IntToFixed(48), FW_IntToFixed(64));
  188.  
  189.         FW_PBitmap bitmap(48, 64, 8);
  190.         
  191.         {
  192.             FW_CBitmapContext bc(ev, bitmap);
  193.             FW_CRectShape::RenderRect(bc, rect, FW_kFill, FW_kWhiteEraseInk);
  194.             
  195.             frame->BuildThumbnail(ev, bc, rect);        
  196.             RenderThumbnailFrame(ev, bc);
  197.         }
  198.         
  199.         fShape = FW_NEW(FW_CBitmapShape, (bitmap, rect));
  200.     }
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    FW_CViewAsThumbnail::CalcUsedShape
  205. //----------------------------------------------------------------------------------------
  206.  
  207. ODShape* FW_CViewAsThumbnail::CalcUsedShape(Environment* ev) const
  208. {
  209.     FW_CPoint thumbnailContour[6] =
  210.         {
  211.             FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(16)),
  212.             FW_CPoint(FW_IntToFixed(32), FW_IntToFixed( 0)),
  213.             FW_CPoint(FW_IntToFixed( 0), FW_IntToFixed( 0)),
  214.             FW_CPoint(FW_IntToFixed( 0), FW_IntToFixed(64)),
  215.             FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(64)),
  216.             FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(16))
  217.         };
  218.  
  219.     ODRgnHandle rgnHandle = FW_CreatePolygonRegion(6, thumbnailContour);
  220.     
  221.     return ::FW_NewODShape(ev, rgnHandle);
  222. }
  223.  
  224. //========================================================================================
  225. // CLASS FW_CViewAsIcon
  226. //========================================================================================
  227.  
  228. //----------------------------------------------------------------------------------------
  229. //    FW_CViewAsIcon::FW_CViewAsIcon
  230. //----------------------------------------------------------------------------------------
  231.  
  232. FW_CViewAsIcon::FW_CViewAsIcon(Environment *ev, FW_CPart* part, short iconSize) :
  233.     FW_CViewAs(ev, part),
  234.     fIconSize(iconSize)
  235. {
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. //    FW_CViewAsIcon::~FW_CViewAsIcon
  240. //----------------------------------------------------------------------------------------
  241.  
  242. FW_CViewAsIcon::~FW_CViewAsIcon()
  243. {
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_CViewAsIcon::LoadIcon
  248. //----------------------------------------------------------------------------------------
  249.  
  250. void FW_CViewAsIcon::Load(Environment* ev, FW_CFrame* frame)
  251. {
  252.     if (fShape == NULL)
  253.     {
  254.         FW_CSharedLibraryResourceFile resourceFile(fPart->GetPartInstance(ev));
  255.         FW_PIcon icon(resourceFile, fPart->GetIconID(ev), fIconSize);
  256.     
  257.         FW_CRect iconRect(FW_kZeroPoint, FW_IntToFixed(fIconSize), FW_IntToFixed(fIconSize));
  258.         fShape = FW_NEW(FW_CIconShape, (icon, iconRect, FW_kIconAlignLeft | FW_kIconAlignTop));
  259.     }
  260. }
  261.  
  262. //----------------------------------------------------------------------------------------
  263. //    FW_CViewAsIcon::CalcUsedShape
  264. //----------------------------------------------------------------------------------------
  265.  
  266. ODShape* FW_CViewAsIcon::CalcUsedShape(Environment* ev) const
  267. {
  268.     FW_ASSERT(fShape != NULL);
  269.     
  270. #ifdef FW_BUILD_MAC
  271.     FW_PIcon icon;
  272.     FW_RenderIconOptions options;
  273.     FW_CRect rect;
  274.     ((FW_CIconShape*)fShape)->GetGeometry(icon, options, rect);
  275.     
  276.     FW_PlatformIcon platformIcon = icon->GetPlatformIcon();
  277.     
  278.     RgnHandle rgn = ::NewRgn();
  279.     FW_SPlatformRect bounds(0, 0, fIconSize, fIconSize);
  280.     ::IconSuiteToRgn(rgn, &bounds, atNone, platformIcon);
  281.     
  282.     return ::FW_NewODShape(ev, rgn);
  283. #endif
  284.  
  285. #ifdef FW_BUILD_WIN
  286.     FW_DEBUG_MESSAGE("Not yet implemented");
  287. #endif
  288. }
  289.  
  290. //========================================================================================
  291. // CLASS FW_CViewAsSmallIcon
  292. //========================================================================================
  293.  
  294. //----------------------------------------------------------------------------------------
  295. //    FW_CViewAsSmallIcon::FW_CViewAsSmallIcon
  296. //----------------------------------------------------------------------------------------
  297.  
  298. FW_CViewAsSmallIcon::FW_CViewAsSmallIcon(Environment *ev, FW_CPart* part) :
  299.     FW_CViewAsIcon(ev, part, 16)
  300. {
  301. }
  302.  
  303. //----------------------------------------------------------------------------------------
  304. //    FW_CViewAsSmallIcon::~FW_CViewAsSmallIcon
  305. //----------------------------------------------------------------------------------------
  306.  
  307. FW_CViewAsSmallIcon::~FW_CViewAsSmallIcon()
  308. {
  309. }
  310.  
  311. //========================================================================================
  312. // CLASS FW_CViewAsLargeIcon
  313. //========================================================================================
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    FW_CViewAsLargeIcon::FW_CViewAsLargeIcon
  317. //----------------------------------------------------------------------------------------
  318.  
  319. FW_CViewAsLargeIcon::FW_CViewAsLargeIcon(Environment *ev, FW_CPart* part) :
  320.     FW_CViewAsIcon(ev, part, 32)
  321. {
  322. }
  323.  
  324. //----------------------------------------------------------------------------------------
  325. //    FW_CViewAsLargeIcon::~FW_CViewAsLargeIcon
  326. //----------------------------------------------------------------------------------------
  327.  
  328. FW_CViewAsLargeIcon::~FW_CViewAsLargeIcon()
  329. {
  330. }
  331.  
  332.